#define _CRT_SECURE_NO_WARNINGS  1

#include<stdio.h>

struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2)
{
    struct ListNode* n1 = list1;
    struct ListNode* n2 = list2;
    struct ListNode* guard = NULL;
    struct ListNode* tail = NULL;
    guard = tail = (struct ListNode*)malloc(sizeof(struct ListNode));
    tail->next = NULL;
    while (n1 && n2)
    {
        if (n1->val > n2->val)
        {
            tail->next = n2;
            tail = tail->next;
            n2 = n2->next;
        }
        else
        {
            tail->next = n1;
            tail = tail->next;
            n1 = n1->next;
        }
    }
    if (n1)
    {
        tail->next = n1;
    }
    if (n2)
    {
        tail->next = n2;
    }
    struct ListNode* head = guard->next;
    free(guard);
    return head;
}